gtk_text_buffer_create_tag(): returns NULL on failure
authorSébastien Wilmet <swilmet@gnome.org>
Thu, 4 Apr 2013 11:30:42 +0000 (13:30 +0200)
committerSébastien Wilmet <swilmet@gnome.org>
Mon, 12 May 2014 17:10:30 +0000 (19:10 +0200)
Returns NULL in case of a duplicated tag name in the tag table. It is
still a programmer error to duplicate a name, but if it happens the
behavior is a little nicer (and hopefully doesn't crash).

https://bugzilla.gnome.org/show_bug.cgi?id=614717

gtk/gtktextbuffer.c

index e562c331ec14304c78ae64b9d3e27718278cd0df..6a03b55f2a3367143a569bc4539327b5fc4568d1 100644 (file)
@@ -2493,7 +2493,11 @@ gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
 
   tag = gtk_text_tag_new (tag_name);
 
-  gtk_text_tag_table_add (get_table (buffer), tag);
+  if (!gtk_text_tag_table_add (get_table (buffer), tag))
+    {
+      g_object_unref (tag);
+      return NULL;
+    }
 
   if (first_property_name)
     {